package com.example.lib.c1;

/**
 * 做到顺序执行 join
 */
public class Main8Join {

    private static class ThreadJoin extends Thread {
        public ThreadJoin(String name) {
            super(name);
        }

        @Override
        public void run() {
            for (int i = 0; i < 100; i++) {
                System.out.println(this.getName() + ":" + i);
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        ThreadJoin thread1 = new ThreadJoin("thread1");
        ThreadJoin thread2 = new ThreadJoin("thread2");
        thread1.start();
        System.out.println("------- 111111");
        /*
        join的意思是 放弃当前线程的执行权，并返回对应线程执行完
        在main线程中调用thread1的join方法，则main线程放弃cpu控制权，并返回thread1继续执行直到thread1执行完毕
         */
        thread1.join();//让t1获取执行权
        System.out.println("------- 222222");
        thread2.start();
    }

}
